$(function () {
comment()
function comment() {
  $.ajax({
    url: `admin/comments`,
    success: function (res) {
      console.log(res);
      let Str = template("assets", res)
      $("#tb").html(Str)
    }


  })

  template.defaults.imports.mytime = function (time) {
    let zero = item => item < 10 ? `0` + item : item
    let newd = new Date(time);
    let n = newd.getFullYear();
    let y = zero(newd.getMonth() + 1);
    let r = zero(newd.getDate());
    let h = zero(newd.getHours());
    let f = zero(newd.getMinutes());
    let s = zero(newd.getSeconds());
    return `${n}-${y}-${r}  ${h}:${f}:${s}`
  }
}



//删除功能

$("#tb").on("click",".del",function (a) {
  a.preventDefault()
  let id = $(this).attr("myid")

//eg1
layer.confirm('是否删除评论?', {
  icon: 3,
  title: '提示'
}, function (index) {
if (index !== 0) {
  

$.ajax({

type: `DELETE`,
url: `admin/comments/${id}`,
success:function (res) {
if (res.status !== 0) {
  return layer.msg(res.message);
}
layer.msg(res.message);
comment()
}
})

}
  layer.close(index);
});


})







})